<?php

    class PANDORA_Prototipos_Email
    {
        protected $form;
        
        public function __construct()
        {
            $this->form = new Zend_Form();
            $this->form->setAction('/contato');
            $this->form->setMethod('post');

            $nome = $this->form->createElement('text','nome',array('label'=>'Seu Nome'));
            $nome->setRequired(true)
             ->addValidator('stringLength',true,array(6,20));

            $email = $this->form->createElement('text','email',array('label' => 'Email'));
            $email->setRequired(true)
              ->addValidator('stringLength',true,array(6,20));

            $conteudo = $this->form->createElement('textarea','conteudo',array('label' => 'Mensagem'));
            $conteudo->setRequired(true)
                ->addValidator('stringLength',true,array(6,1000));

            $this->form->addElement($nome);
            $this->form->addElement($email);
            $this->form->addElement($conteudo);
            $this->form->addElement('submit','enviar',array('label' => 'Enviar'));

            echo $this->form;
        }
        
        public function dataValidation($data)
        {
            if($this->form->isValid($data))
                return true;
            
            return false;
        }
        
        public function sendEmail($body)
        {
            $config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login', 'username' => 'contatos.clientes.pandora@gmail.com', 'password' => '&7id1q3q**hTlm3b');
            $transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
            Zend_Mail::setDefaultTransport($transport);
            $mail = new Zend_Mail();
            $mail->setBodyText($body);    
            $mail->addTo('jean.machado@bento.ifrs.edu.br');
            $mail->setSubject('E-mail');
            if($mail->send())
                return true;
            
            return false;
        }
    }